<script>
  function ShowOptions(theType) {
    theType = parseInt(theType);
    /*
     cody.Meta.Generator.textinput
     cody.Meta.Generator.textareainput
     cody.Meta.Generator.numberinput
     cody.Meta.Generator.dateinput
     cody.Meta.Generator.date3input
     cody.Meta.Generator.selectinput
     cody.Meta.Generator.radioinput
     cody.Meta.Generator.checkboxinput
     cody.Meta.Generator.submitbutton
     */
    if (theType === <%=cody.Meta.Generator.textinput%>) { // text input
      $('#mindiv').show();
      $('#mindiv label').html("Minimum chars");
      $('#maxdiv').show();
      $('#maxdiv label').html("Maximum chars");
      $('#requireddiv').show();
      $('#textvalidationdiv').show();
      $('#numbervalidationdiv').hide();
      $('div.choices').hide();

    } else if (theType === <%=cody.Meta.Generator.textareainput%>) { // text area
      $('#mindiv').show();
      $('#mindiv label').html("Nr of chars");
      $('#maxdiv').show();
      $('#maxdiv label').html("Nr of lines");
      $('#requireddiv').show();
      $('#textvalidationdiv').show();
      $('#numbervalidationdiv').hide();
      $('div.choices').hide();

    } else if (theType === <%=cody.Meta.Generator.numberinput%>) { // number text input
      $('#mindiv').show();
      $('#mindiv label').html("Minimum");
      $('#maxdiv').show();
      $('#maxdiv label').html("Maximum");
      $('#requireddiv').show();
      $('#textvalidationdiv').hide();
      $('#numbervalidationdiv').show();
      $('div.choices').hide();

    } else if (theType === <%=cody.Meta.Generator.dateinput%>) { // date input
      $('#mindiv').hide();
      $('#maxdiv').hide();
      $('#requireddiv').show();
      $('#textvalidationdiv').hide();
      $('#numbervalidationdiv').hide();
      $('div.choices').hide();

    } else if (theType === <%=cody.Meta.Generator.date3input%>) { // 3 date part input
      $('#mindiv').hide();
      $('#maxdiv').hide();
      $('#requireddiv').show();
      $('#textvalidationdiv').hide();
      $('#numbervalidationdiv').hide();
      $('div.choices').hide();

    } else if (theType === <%=cody.Meta.Generator.selectinput%>) { // popup menu
      $('#mindiv').hide();
      $('#maxdiv').hide();
      $('#requireddiv').show();
      $('#textvalidationdiv').hide();
      $('#numbervalidationdiv').hide();
      $('div.choices').show();

    } else if (theType === <%=cody.Meta.Generator.radioinput%>) { // radio buttons
      $('#mindiv').hide();
      $('#maxdiv').hide();
      $('#requireddiv').show();
      $('#textvalidationdiv').hide();
      $('#numbervalidationdiv').hide();
      $('div.choices').show();

    } else if (theType === <%=cody.Meta.Generator.checkboxinput%>) { // check boxes
      $('#mindiv').hide();
      $('#maxdiv').hide();
      $('#requireddiv').hide();
      $('#textvalidationdiv').hide();
      $('#numbervalidationdiv').hide();
      $('div.choices').show();

    }

    return true;
  }
  function copyColumn() {
    $("#name").val($("#usercolumns").val());
    $("#usercolumns").val(0);
  }

</script>


<div id="content_data">
  <form action="./forms" method="post" class="clearfix" name="onepage" id="onepage" enctype="multipart/form-data">
    <input type="hidden" name="request" id="request" value="save" />
    <input type="hidden" name="node" value="<%= atom.id %>" />
    <input type="hidden" name="extention" value="<%= atom.extention %>" />

    <fieldset id="tabs">
      <div id="options" class="horizontal">

        <% if (atom.extention === "") { %>
          <div>
            <label for="name"><%= __("Name")%></label>
            <input name="name" id="name" type="text" value="<%= object.name %>" size="40" />
          </div>
          <div>
            <label for="alert"><%= __("Warn email")%> </label>
            <input name="alert" id="alert" type="text" value="<%= object.alert %>" size="40" />
          </div>
          <% for (var iL in app.languages) { var L = app.languages[iL]; %>
            <div id="labeldiv-<%= L.id %>" class="labels">
              <label for="label-<%= L.id %>"><%= __("Button")%> <%= L.name %></label>
              <input name="label-<%= L.id %>" id="label-<%= L.id %>" type="text" value="<%= object.labels[L.id] %>" size="62" />
            </div>
          <% } %>

        <% } else { %>

          <div>
            <label for="name"><%= __("Name")%></label>
            <input name="name" id="name" type="text" value="<%= object.name %>" size="40" />
            <select onchange="copyColumn()" id="usercolumns"><option value="0">-- prefill with --</option>
              <% var user = getLogin();
              for (var iU in user) { if (typeof user[iU] !== "function") { %>
              <option value="<%= iU %>"><%= iU %></option>
              <% } } %>
            </select>
          </div>

          <div id="generatordiv">
            <label for="generator"><%= __("Type")%></label>
            <select name="generator" id="generator" onchange="return ShowOptions(this.value);">
              <option value="<%=cody.Meta.Generator.textinput%>" <%= (object.generator === cody.Meta.Generator.textinput) ? 'selected' : '' %>>Text line</option>
              <option value="<%=cody.Meta.Generator.textareainput%>" <%= (object.generator === cody.Meta.Generator.textareainput) ? 'selected' : '' %>>Text block</option>
              <option value="<%=cody.Meta.Generator.numberinput%>" <%= (object.generator === cody.Meta.Generator.numberinput) ? 'selected' : '' %>>Number</option>
              <option value="<%=cody.Meta.Generator.dateinput%>" <%= (object.generator === cody.Meta.Generator.dateinput) ? 'selected' : '' %>>Date</option>
              <option value="<%=cody.Meta.Generator.date3input%>" <%= (object.generator === cody.Meta.Generator.date3input) ? 'selected' : '' %>>Day Month Year</option>
              <option value="<%=cody.Meta.Generator.selectinput%>" <%= (object.generator === cody.Meta.Generator.selectinput) ? 'selected' : '' %>>Popup menu</option>
              <option value="<%=cody.Meta.Generator.radioinput%>" <%= (object.generator === cody.Meta.Generator.radioinput) ? 'selected' : '' %>>Radio buttons</option>
              <option value="<%=cody.Meta.Generator.checkboxinput%>" <%= (object.generator === cody.Meta.Generator.checkboxinput) ? 'selected' : '' %>>Check boxes</option>
            </select>
          </div>

          <div id="defaultdiv">
            <label for="default"><%= __("Default value")%> </label>
            <input name="default" id="default" type="text" value="<%= val(object.options.default) %>" />
          </div>

          <div id="mindiv">
            <label for="min"><%= __("Min / Length")%></label>
            <input name="min" id="min" type="text" value="<%= val(object.min) %>" size="4" />
          </div>
          <div id="maxdiv">
            <label for="max"><%= __("Max / Lines")%> </label>
            <input name="max" id="max" type="text" value="<%= val(object.max) %>" size="4" />
          </div>
          <div id="requireddiv">
            <label for="required"><%= __("Required")%></label>
            <input name="required" id="required" type="checkbox" value="Y" <%= (object.options.required) ? 'checked' : '' %> />
          </div>

          <div id="textvalidationdiv">
            <label for="no"><%= __("Validation")%></label>
            <div class="radios">
              <input name="validation" id="no" type="radio" value="X" <%= ((!object.options.number) && (! object.options.email) && (! object.options.phone)) ? 'checked' : '' %> />
              <label for="no"><%= __("No")%></label>
              <input name="validation" id="email" type="radio" value="E" <%= (object.options.email) ? 'checked' : '' %> />
              <label for="email"><%= __("Email")%></label>
              <input name="validation" id="phone" type="radio" value="P" <%= (object.options.phone) ? 'checked' : '' %> />
              <label for="phone"><%= __("Phone")%></label>
            </div>
          </div>

          <div id="numbervalidationdiv">
            <label for="email"><%= __("Validation")%></label>
            <div class="radios">
              <input name="validation" id="integer" type="radio" value="I" <%= (object.reader == cody.Meta.Reader.integer) ? 'checked' : '' %> />
              <label for="integer"><%= __("Whole number")%> </label>
              <input name="validation" id="number" type="radio" value="N" <%= (object.reader == cody.Meta.Reader.number) ? 'checked' : '' %> />
              <label for="number"><%= __("Allow decimals")%> </label>
            </div>
          </div>

          <% for (var iL in app.languages) { var L = app.languages[iL]; %>
            <div><label class="language"><%= L.name %></label></div>
            <div id="labeldiv-<%= L.id %>" class="labels">
              <label for="label-<%= L.id %>"> - <%= __("Label")%></label>
              <input name="label-<%= L.id %>" id="label-<%= L.id %>" type="text" value="<%= object.labels[L.id] %>" size="62" />
            </div>
            <div id="choicediv-<%= L.id %>" class="choices">
              <label for="choice-<%= L.id %>"> - <%= __("Choices")%></label>
              <textarea name="choice-<%= L.id %>" id="choice-<%= L.id %>" cols="62" rows="6"><%= (typeof object.options.choices === "undefined") ? "" : object.options.choices[L.id] %></textarea>
            </div>
          <% } %>

        <% } %>
      </div>
    </fieldset>

    <div id="action_buttons">
      <button id="doSave"><%= __("Save")%></button>
      <button id="doRealDelete"><%= __("Delete")%></button>
    </div>
  </form>
</div>